// subpackagesA/pages/newfolder/newfolder.ts
import {findMaintenanceCause,findReasonByID} from '../../../api/room-monitoring'
import { getCurrentPage } from '../../../miniprogram_npm/@vant/weapp/common/utils'
Page({

    /**
     * 页面的初始数据
     */
    data: {
      items:[
      ],
      list:[],
      comID:-1,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {

    },
    onClickLeft(){
      wx.navigateBack({
        delta:1,
      })
    },
    onClickNav(e:any){
      console.log(e)
      const index = e.detail
      const id = this.data.items[index].id
      const comID = this.data.comID
      findReasonByID(id,comID).then((res:any)=>{
        const list = res.data.map((item,index)=>{
          return{
            text:item.reasonShow,
            title:item.title,
            id:index
          }
        })
        this.setData({
          list:list
        })
        console.log(list)
      })
    },
    onTab(e:any){
      console.log(e)
      const {item} = e.currentTarget.dataset
      const pages = getCurrentPages();
      const currentTarget = pages[pages.length-1];
      const prevPage = pages[pages.length - 2];
      prevPage.setData({
        repairReason:item
      })
      wx.navigateBack({
        delta:1
      })
    },
    onClickItem(e:any){
      console.log(e)
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监
     * 听页面显示
     */
    onShow() {
      this.setData({
        comID: wx.getStorageSync("userInfo").data.comID,
      })
      const comID = this.data.comID
      
       findMaintenanceCause(comID).then((res:any)=>{
        const list = res.data.map((item,index)=>{
          return{
            text:item.types,
            id:item.id,
            index:index,
            children:[]
          }
        })
        this.setData({
          items:list
        })
        const id = this.data.items[0].id
         findReasonByID(id,comID).then((res:any)=>{
          const list = res.data.map((item,index)=>{
            return{
              text:item.reasonShow,
              title:item.title,
              id:index
            }
          })
          this.setData({
            list:list
          })
          console.log(list)
        })
      })


    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})